package com.marketingexpert.controller.streammgnt;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class DateFormateController implements Controller {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0); 
		PrintWriter out = response.getWriter();
		
		String date = request.getParameter("date");
		String suffix  = request.getParameter("suffix"); 
		Date d = new Date(date);
		date = sdf.format(d);
		
		DateMap dm = new DateMap(date, suffix);
		JSONObject json = JSONObject.fromObject(dm);
		out.print(JSONObject.fromObject(dm));
		return null;
	}
	
	public class DateMap{
		private String date;
		
		private String suffix;
		
		public DateMap(String date, String suffix) {
			this.date = date;
			this.suffix = suffix;
		}

		public String getDate() {
			return date;
		}

		public void setDate(String date) {
			this.date = date;
		}

		public String getSuffix() {
			return suffix;
		}

		public void setSuffix(String suffix) {
			this.suffix = suffix;
		}
		
		
	}

}
